package com.epfresh.supplier.entity;

import android.graphics.Color;

import com.epfresh.api.utils.FormatUtil;
import com.epfresh.api.utils.JsonUtils;


/**
 * @author wangzhanghuan
 * @version 1.0
 * @date create 17-8-18
 * @Description
 */

public class Goods {

    /* {
       "id" : 3971,
       "title" : "小白南瓜子",
       "createdTime1" : "2017-04-23 16:08:11",
       "price" : 8.80,
       "packageSize" : 1.00,
       "packageUnit" : "斤",
       "packageContainer" : "散货",
       "type" : "1",
       "status" : 1,
       "moq" : 10.00,
       "deposit" : null,
       "inventory" : 99999.00,
       "chargeUnit" : "斤",
       "deliveryTime" : null,
       "date" : null,
       "createdTime" : null,
       "thumbnail" : "http://imgtest.epfresh.com/2017%2F4%2F23%2F1492934894873_QQ%E6%88%AA%E5%9B%BE20170423160725.png-PRODUCTTHUMBNAIL",
       "color" : " 0xf01700",
       "message" : "进货信息159天未更新，有更新，有销量！"
     }
 */

    /*
    *当前变价单位 priceUnit
    *当前价格 priceNow
    * */

    private Double priceNow;
    private Double priceUnit = 0.01;


    private String upstreamMarket;
    private String origin;
    private String quantity;
    private String key;
    private String keyTop;
    private String keyTwo;

    public String getKeyTop() {
        return keyTop;
    }

    public void setKeyTop(String keyTop) {
        this.keyTop = keyTop;
    }

    public String getKeyTwo() {
        return keyTwo;
    }

    public void setKeyTwo(String keyTwo) {
        this.keyTwo = keyTwo;
    }

    public Double getPriceUnit() {
        return priceUnit;
    }

    public void setPriceUnit(Double priceUnit) {
        this.priceUnit = priceUnit;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getUpstreamMarket() {
        return upstreamMarket;
    }

    public void setUpstreamMarket(String upstreamMarket) {
        this.upstreamMarket = upstreamMarket;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public Double getPriceNow() {
        return priceNow;
    }

    public void setPriceNow(Double priceNow) {
        this.priceNow = priceNow;
    }

    private String id;
    private String message;
    private String color;

    private String title;
    private String thumbnail;
    private Double price;
    private String lastSnapshotId;
    private Double inventory;
    private Double incr;
    private Double moq;
    private String pack;
    private String chargeUnit;
    private String packageUnit;
    private String packageContainer;
    private String packageSize;
    //促销id
    private String promotionItemId;
    //销售类型
    private String type;

    private double productCount;
    //商品数量增减前的数量
    private double productCountLast;
    //在list中的位置
    private int position;

    public void addIncr() {
        productCountLast = productCount;
        productCount = FormatUtil.countAdd(productCount, getIncr());
        long l = FormatUtil.remainderZero(productCount, getMoq());
        if (l  < 0){
            productCount = getMoq();
        }
    }

    public void minusIncr() {
        productCountLast = productCount;
        long l = FormatUtil.remainderZero(productCount, getMoq());
        if (l < 0) {
            productCount = 0;
        } else {
            productCount = FormatUtil.countAdd(productCount, -getIncr());
        }
    }

    public boolean isLegal(double d) {
        boolean remainder = FormatUtil.isRemainder(d, getIncr(), getMoq());
        if (!remainder) {
            return true;
        }
        return false;
    }
    public double legalCnt(double d) {
        return FormatUtil.countFormat(d,getIncr(),getMoq());
    }

    public String getType() {
        return type;
    }

    public Double getInventory() {
        return inventory==null?0:inventory;
    }

    public void setInventory(Double inventory) {
        this.inventory = inventory;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Double getMoq() {
        return moq == null ? 0 : moq;
    }

    public void setMoq(Double moq) {
        this.moq = moq;
    }

    public double getProductCount() {
        return productCount;
    }

    public void setProductCount(double productCount) {
        this.productCountLast = productCount;
        this.productCount = productCount;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getThumbnail() {
        return thumbnail;
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public String getLastSnapshotId() {
        return lastSnapshotId;
    }

    public void setLastSnapshotId(String lastSnapshotId) {
        this.lastSnapshotId = lastSnapshotId;
    }

    public Double getIncr() {
        return (incr == null || incr == 0)? 1 : incr;
    }

    public void setIncr(Double incr) {
        this.incr = incr;
    }

    public String getPack() {
        return pack;
    }

    public void setPack(String pack) {
        this.pack = pack;
    }

    public String getChargeUnit() {
        return chargeUnit;
    }

    public void setChargeUnit(String chargeUnit) {
        this.chargeUnit = chargeUnit;
    }

    public double getProductCountLast() {
        return productCountLast;
    }

    public void setProductCountLast(double productCountLast) {
        this.productCountLast = productCountLast;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public String getPromotionItemId() {
        return promotionItemId;
    }

    public void setPromotionItemId(String promotionItemId) {
        this.promotionItemId = promotionItemId;
    }

    @Override
    public String toString() {
        return JsonUtils.toJson(this);
    }

    public String getPriceStr() {
        if (price ==null){
            price = 0.00;
        }
        return String.format("%.2f",price) + "元/" + chargeUnit;
    }
    public String getPriceUnitStr() {

        return  "元/" + chargeUnit;
    }
    public String getPackStr() {

        if ("散货".equals(packageContainer)){
            return packageSize+packageUnit;
        }
        return packageSize+packageUnit+ "/" + packageContainer;
    }


    public String getKey() {
        if (id == null || "".equals(id)){
            return "";
        }
        String s = promotionItemId == null ? "" : promotionItemId;
        return id + "-" + s;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getColor() {

        return color;
    }
    public int getColorInt() {
        String c = "#626262";
        if (color != null){
            c = color.trim().replace("0x","#");
        }


        int cc = 0xff626262;
        if (c != null) {
            try {
                cc = Color.parseColor(c);;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return cc;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getPackageUnit() {
        return packageUnit;
    }

    public void setPackageUnit(String packageUnit) {
        this.packageUnit = packageUnit;
    }

    public String getPackageContainer() {
        return packageContainer;
    }

    public void setPackageContainer(String packageContainer) {
        this.packageContainer = packageContainer;
    }

    public String getPackageSize() {
        return packageSize;
    }

    public void setPackageSize(String packageSize) {
        this.packageSize = packageSize;
    }
}
